//
//  LoopView_Model.m
//  International_Hospital
//
//  Created by LiYiLin on 16/7/5.
//  Copyright © 2016年 LiYiLin. All rights reserved.
//

#import "LoopView_Model.h"
#import "NetWorkTools.h"

@implementation LoopView_Model

+ (instancetype)modelWithDictionary:(NSDictionary *)dic {
    
    LoopView_Model * model = [[LoopView_Model alloc] init];
    [model setValuesForKeysWithDictionary:dic];
    return model;
}

- (NSString *)description {
    return [NSString stringWithFormat:@"%@{imgsrc = %@}",[super description],self.imgsrc];
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{}

+ (void)loopView_ModelWithSuccess:(void (^)(NSArray<LoopView_Model *> *))successBlock error:(void (^)())errorBlock {
    
    [[NetWorkTools sharedTools]GET:@"ad/headline/0-4.html" parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *  _Nullable responseObject) {
        
        NSString * rootkey = responseObject.keyEnumerator.nextObject;
        NSArray * array = responseObject[rootkey];
        NSMutableArray * mutableArray = [NSMutableArray array];
        
        [array enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            LoopView_Model * model = [LoopView_Model modelWithDictionary:obj];
            
            [mutableArray addObject:model];
        }];
        if (successBlock) {
            successBlock(mutableArray.copy);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        if (errorBlock) {
            errorBlock();
        }
    }];
}

@end
